//
//  ExchangeAddViewController.m
//  LineMoney
//
//  Created by 范琦 on 16/7/15.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "ExchangeAddViewController.h"
#import "ExchangeTwoCell.h"

@interface ExchangeAddViewController ()<UITableViewDataSource, UITableViewDelegate, UIPickerViewDataSource, UIPickerViewDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSArray *arr1;
@property (nonatomic, strong) NSArray *arr2;
@property (nonatomic, strong) NSArray *arr3;

@property (nonatomic, strong) UIPickerView *pickView;
@property (nonatomic, strong) NSMutableArray *yearArr;

@property (nonatomic, strong) NSString *str;

@end

@implementation ExchangeAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = [NSString stringWithFormat:@"添加%@账户",self.str1];
    self.str = @"CD";
    [self creatPickerView];
    [self creatTableView];
    [self creatRightBtn];
    
}
- (void)creatRightBtn
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 30);
    UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithCustomView:button];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    [button setTitle:@"保存" forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = btn;
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    
}
- (void)creatTableView
{
    self.arr1 = @[@"姓名",@"电话",@"邮箱地址"];
    self.arr2 = @[@"选择国家", @"城市", @"省", @"州", @"邮编"];
    self.arr3 = @[@"银行名",@"银行卡号"];

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT - 64) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    _tableView.rowHeight = 55;
    [_tableView registerNib:[UINib nibWithNibName:@"ExchangeTwoCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    _tableView.backgroundColor = HUIBACKGROUNDCOLOR;
    
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.sectionFooterHeight = 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 3;
    }else if (section == 1){
        return 5;
    }
    
    return 2;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ExchangeTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.imageV.hidden = YES;
    if (indexPath.section == 0) {
        cell.label.text = _arr1[indexPath.row];
    }else if (indexPath.section == 1){
    
        cell.label.text = _arr2[indexPath.row];
        if (indexPath.row != 4) {
            cell.imageV.hidden = NO;
            cell.text.inputView = _pickView;
            [[cell.text rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
                cell.text.text = _str;
            }];
        }
    
    }else{
        cell.label.text = _arr3[indexPath.row];
        if (indexPath.row == 0) {
            cell.imageV.hidden = NO;
            cell.text.placeholder = @"请选择";
            cell.text.inputView = _pickView;
            [[cell.text rac_signalForControlEvents:UIControlEventEditingDidEnd] subscribeNext:^(id x) {
                cell.text.text = _str;
            }];
            
        }
        
    }
    
    
    return cell;
}

#warning 创建PickerView
- (void)creatPickerView
{
    self.yearArr = [NSMutableArray arrayWithObjects:@"CD",@"CD",@"CD", nil];
    self.pickView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, KSCREENHEIGHT - 150, KSCREENWIDTH, 150)];
    _pickView.delegate = self;
    _pickView.dataSource = self;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return 3;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{

    return _yearArr[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
    _str = _yearArr[row];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
